#pragma once
#include <conio.h>
#include <iostream>
#include "Console.h"
#include <mutex>
#include <deque>
#include <thread>
#include <string>
using namespace std;

mutex mutex_cout;

struct Position
{
public:
	int posX = 0;
	int	posY = 0;
	int prevX = 1;
	int	prevY = 1;
	string name;
};

deque<Position> PositionQueue;
deque<char> player1input;
deque<char> player2input;

class Game
{
private:
	
public:
	Game()
	{
	}

	void paintboard()
	{
		Course::Console::gotoxy(10, 0);
		for (int i = 0; i < 20; i++)
		{
			cout << "|";
			Course::Console::gotoxy(10, i + 1);
		}
		Course::Console::gotoxy(40, 0);
		for (int i = 0; i < 20; i++)
		{
			cout << "|";
			Course::Console::gotoxy(40, i + 1);
		}
		Course::Console::gotoxy(10, 20);
		for (int i = 0; i < 30; i++)
		{
			cout << "-";
		}

		if (PositionQueue.empty() == false)
		{
		
			Position temp = PositionQueue.front();
			Course::Console::gotoxy(temp.prevX, temp.prevY);
			cout << " ";
			Course::Console::gotoxy(temp.posX, temp.posY);
			cout << temp.name;
			PositionQueue.pop_front();
		}
	}
	void operator()()
	{
		char Input;
		
		while (1)
		{
			mutex_cout.lock();
			if (_kbhit())
			{
				Input = _getch();


				if (Input == 'w' || Input == 'a' || Input == 's' || Input == 'd')
				{
					player1input.push_front(Input);
				}

				if (Input == 'i' || Input == 'j' || Input == 'k' || Input == 'l')
				{
					player2input.push_front(Input);
				}

			}
			
			paintboard();
			mutex_cout.unlock();
			this_thread::sleep_for(chrono::milliseconds(50));
		}

	}
	void Gameover()
	{
		mutex_cout.unlock();
		exit(EXIT_SUCCESS);
	}


	~Game()
	{
	}
};

